<?php
class CProductaccessory extends Zend_Db_Table{
	protected $_name;
	protected $_primary;
	public function __construct()
	{
		$this->_name=R_PRE. "product_accessory";
		parent::__construct();
	}
	function getAccessoryInfo($accessoryid,$itemid='',$flid=''){
		$db=$this->getAdapter();
		$select = $db->select();
		$select->from('zcshop_product_accessory', '*');
		if(!empty($itemid)){
			$select->where('zcshop_product_accessory.accessoryid = '.$accessoryid.' and zcshop_product_accessory.itemid='.$itemid);
		}else if(!empty($flid)){
			$select->where('zcshop_product_accessory.accessoryid = '.$accessoryid.' and zcshop_product_accessory.flid='.$flid);
		}else{
			$select->where('zcshop_product_accessory.accessoryid = '.$accessoryid);
		}
		$select->join('zcshop_items', 'zcshop_items.itemid = zcshop_product_accessory.accessoryid', '*')->join('zcshop_products', 'zcshop_items.itemid = zcshop_products.itemid', '*');
		$result=$db->fetchRow($select);
		return $result;
	}
	function getProductAccessory($itemid){
		$db=$this->getAdapter();
		$select = $db->select();
		$select->from('zcshop_product_accessory', '*');
		$select->where('zcshop_product_accessory.itemid = '.$itemid.' and zcshop_products.is_showed=1');
		$select->join('zcshop_items', 'zcshop_items.itemid = zcshop_product_accessory.accessoryid', '*')->join('zcshop_products', 'zcshop_items.itemid = zcshop_products.itemid', '*');
		$result=$db->fetchAll($select);
		return $result;
	}
	public function createProductAccessory($data){
		$accessoryid=$this->insert($data);
		
		return $accessoryid;
	}
	public function getFenleiAccessory($flid){
		if(empty($flid)){
			return false;
		}
		$db=$this->getAdapter();
		$select = $db->select();
		$select->from('zcshop_product_accessory', '*');
		$select->where('zcshop_product_accessory.flid='.$flid.' and zcshop_products.is_showed=1');
		$select->join('zcshop_products', 'zcshop_products.itemid = zcshop_product_accessory.accessoryid', 'productid');
		$result=$db->fetchAll($select);
		return $result;
	}
	public function delProductAccessory($itemid){
		$where ="itemid=$itemid";
		$res = $this->delete($where);
		return $res;
	}
	public function delFlidAccessory($flid){
		$where ="flid=$flid";
		$res = $this->delete($where);
		return $res;
	}
}
